import axios from "axios";
// 下载文件（可解决跨域下载问题）]
axios.defaults.baseURL = '/photo'
export async function downloadFile(fileUrl, fileName) {
    if (!fileUrl) return;
    let res = await axios({
        method: "get",
        url: fileUrl,
        responseType: "blob"
    });
    let newUrl = window.URL.createObjectURL(res.data);
    let a = document.createElement("a");
    a.href = newUrl;
    a.download = fileName;
    a.click();
    a.remove();
    //在资源下载完成后 可以人工清除createObjectURL 占用的缓存资源
    window.URL.revokeObjectURL(newUrl);
}
